package com.seata.demo.order.config;

import feign.RequestInterceptor;
import io.seata.core.context.RootContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 确保Feign调用时传递Seata的xid
 */
@Configuration
public class FeignConfig {

    @Bean
    public RequestInterceptor seataRequestInterceptor() {
        return template -> {
            // 将Seata的事务ID放入请求头
            String xid = RootContext.getXID();
            if (xid != null) {
                template.header(RootContext.KEY_XID, xid);
            }
        };
    }
}
